let app = getApp();
var applet_park_api_url = app.globalData.applet_park_api_url;
var applet_park_api_url_imgUrl = app.globalData.applet_park_api_url_imgUrl;
var util = require('../../../utils/util.js');
const {
  requestDataparams
} = require('../../../utils/request.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: applet_park_api_url_imgUrl,
    dynamiclist: [],
    nowPeopleNum: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getLists();
    that.getContainNum();
  },
  getLists() {
    var that = this;
    requestDataparams('/api/information/queryIssueInformationList', {
      type: 4
    }, 'POST', 'json').then(response => {
      if (response.data.code == 0) {
        for (var i = 0; i < response.data.data.records.length; i++) {
          response.data.data.records[i].actTime = response.data.data.records[i].actTime.substring(0, 16);
        }
        that.setData({
          dynamiclist: response.data.data.records
        })
      } else {
        wx.showToast({
          title: '失败',
          icon: 'none'
        })
      }
    })
  },
  enterPolicydatail(e) {
    var that = this
    if(util.formatTime(new Date())>that.data.dynamiclist[e.currentTarget.dataset.index].actTime){
      wx.showToast({
        title: '该活动已结束',
        icon: 'none'
      })
      return
    }
    wx.navigateTo({
      url: '../parkActivityDetalis/parkActivityDetalis?id=' + e.currentTarget.dataset.id
    })
  },
  getContainNum() { //获取当前报名人数
    var that = this;
    var url = '/api/information/queryContainNum/' + that.data.dynamiclist.id;
    requestDataparams(url, {}, 'POST', 'json').then(response => {
      if (response.data.code == 0) {
        that.setData({
          nowPeopleNum: response.data.data
        })
      } else {
        wx.showToast({
          title: '失败',
          icon: 'none'
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})